
package org.sopt.dev.ImgKnight.monitor.operation;

import org.jboss.netty.channel.Channel;

public class Operations {

	public final static String opInfoAgent = "info:agent";
	
	public final static String opInfoCondition = "info:condition";
	
	public final static String opInfoAgentTrafic = "info:agent-trafic";
	
	public final static String opInfoHighPrioUrl = "info:highprio-url";
	
	public final static String opInfoAllowPattern = "info:allow-pattern";
	
	public final static String opInfoDenyPattern = "info:deny-pattern";
	
	public final static String opSleep = "sleep:";
	
	public final static String opAddHighPrioUrl = "add:highprio-url";
	
	public final static String opAddAllowPattern = "add:allow-pattern";
	
	public final static String opAddDenyPattern = "add:deny-pattern";
	
	public final static String opRmUrl = "rm:url";
	
	public final static String opInfoTrafic = "info:trafic";
	
	public final static String opRunGC = "run:gc";
	
	public static void infoAgent(Channel peer) {
		peer.write(opInfoAgent+"\r\n");
	}
	
	public static void infoCondition(Channel peer) {
		peer.write(opInfoCondition+"\r\n");
	}
	
	public static void infoAgentTrafic(Channel peer) {
		peer.write(opInfoAgentTrafic+"\r\n");
	}
	
	public static void infoHighPrioUrl(Channel peer) {
		peer.write(opInfoHighPrioUrl+"\r\n");
	}
	
	public static void infoAllowPattern(Channel peer) {
		peer.write(opInfoAllowPattern+"\r\n");
	}
	
	public static void infoDenyPattern(Channel peer) {
		peer.write(opInfoDenyPattern+"\r\n");
	}
	
	public static void sleep(Channel peer, int millisec) {
		peer.write(opSleep+millisec+"\r\n");
	}
	
	public static void addAllowPattern(Channel peer, String patterns) {
		peer.write(opAddAllowPattern+" "+patterns+"\r\n");
	}
	
	public static void addDenyPattern(Channel peer, String patterns) {
		peer.write(opAddDenyPattern+" "+patterns+"\r\n");
	}
	
	public static void addHighPrioUrl(Channel peer, String url) {
		peer.write(opAddHighPrioUrl+" "+url+"\r\n");
	}
	
	public static void removeUrl(Channel peer, String url) {
		peer.write(opRmUrl+" "+url+"\r\n");
	}
	
	public static void infoTrafic(Channel peer) {
		peer.write(opInfoTrafic+"\r\n");
	}
	
	public static void runGC(Channel peer) {
		peer.write(opRunGC+"\r\n");
	}
	
	public static String getHeader(String response) {
		if( response == null || response.equals("") )
			return null;
		try {
			return response.substring(0, response.indexOf("="));
		} catch (Exception e) {
			return null;
		}
	}
	
	public static String sliceHeder(String response) {
		if( response == null || response.equals("") )
			return null;
		try {
			return response.substring(response.indexOf("=")+1);
		} catch (Exception e) {
			return null;
		}
	}
}
